package com.smartwasser.yunhtgl.apphtgl.asps;

import android.app.Dialog;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;

import com.smartwasser.yunhtgl.apphtgl.R;
import com.smartwasser.yunhtgl.apphtgl.base.BaseActivity;
import com.smartwasser.yunhtgl.apphtgl.bean.SPGreat4Bean;
import com.smartwasser.yunhtgl.apphtgl.function.OfficeReader;
import com.smartwasser.yunhtgl.apphtgl.presenter.SPGreat4Presenter;
import com.smartwasser.yunhtgl.apphtgl.presenter.SPGreat4PresenterImpl;
import com.smartwasser.yunhtgl.apphtgl.view.SPGreat4View;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.dou361.dialogui.DialogUIUtils.dismiss;
import static com.smartwasser.yunhtgl.apphtgl.utils.SharedUtils.getStringData;
import static com.smartwasser.yunhtgl.apphtgl.utils.TypeUtils.getPath;
import static com.smartwasser.yunhtgl.apphtgl.utils.TypeUtils.getQicaoType;
import static com.smartwasser.yunhtgl.apphtgl.utils.TypeUtils.getSZType;
import static com.smartwasser.yunhtgl.apphtgl.utils.TypeUtils.getType;

/**
 * 已终止合同详情接口
 * 已终止合同
 * 一般合同详情
 */
public class SPCase4Activity extends BaseActivity implements SPGreat4View {
    private SPGreat4Presenter sp1Great4Presenter = new SPGreat4PresenterImpl(this);
    private SPGreat4Bean spGreat4Bean;
    private Dialog loadingHorizontal;
    private String id;
    @BindView(R.id.tv_toolbar)
    TextView tv_toolbar;
    @BindView(R.id.sp1_normal_scroll)
    ScrollView sp1_normal_scroll;
    @BindView(R.id.sp1_normal_name)
    TextView sp1_normal_name;//合同名称
    @BindView(R.id.sp1_normal_code)
    TextView sp1_normal_code;//合同编号
    @BindView(R.id.sp1_great_sq)
    TextView sp1_great_sq;//合同申请部室
    @BindView(R.id.sp1_great_zgy)
    TextView sp1_great_zgy;//合同专管员
    @BindView(R.id.sp1_great_creat_time)
    TextView sp1_great_creat_time;//合同申请时间
    @BindView(R.id.sp1_great_fen)
    TextView sp1_great_fen;//合同份数
    @BindView(R.id.sp1_normal_main)
    TextView sp1_normal_main;//授权签署人
    @BindView(R.id.sp1_normal_yj)
    TextView sp1_normal_yj;//单位负责人意见
    @BindView(R.id.sp1_normal_fg)
    TextView sp1_normal_fg;//集团分管领导
    @BindView(R.id.sp1_normal_fg_yj)
    TextView sp1_normal_fg_yj;//集团分管领导意见
    @BindView(R.id.sp1_great_bz)
    TextView sp1_great_bz;//备注
    @BindView(R.id.sp1_great_qc)
    TextView sp1_great_qc;//起草
    @BindView(R.id.sp1_great_zw)
    TextView sp1_great_zw;//正文
    @BindView(R.id.sp1_great_yj)
    TextView sp1_great_yj;//法律意见书
    @BindView(R.id.sp1_great_sz)
    TextView sp1_great_sz;//收支情况
    @BindView(R.id.sp1_great_lx)
    TextView sp1_great_lx;//合同类型
    @BindView(R.id.sp1_great_qz)
    TextView sp1_great_qz;//签字盖章

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_sp_case2);
        ButterKnife.bind(this);
    }

    @Override
    public void initView() {
        tv_toolbar.setText("一般合同详情");
        sp1_normal_scroll.setVisibility(View.INVISIBLE);
        id = getIntent().getStringExtra("id");
    }

    @Override
    public void initData() {
        loadingHorizontal = showLoadingHorizontal(this, "加载中...").show();
        try {
            sp1Great4Presenter.getType1Sp1Great4(getStringData(this, "JSESSIONID", ""), id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @OnClick({R.id.back, R.id.sp1_great_zw_all})
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.sp1_great_zw_all:
                if (null != spGreat4Bean.getBuContractBaseInfo()) {
                    String path = spGreat4Bean.getBuContractBaseInfo().getPath();
                    if (!path.isEmpty() && path.length() > 0) {
                        startActivity(OfficeReader.class, "url", path);
                    } else {
                        showResult("暂无数据");
                    }
                } else {
                    showResult("暂无数据");
                }
                break;
        }
    }

    @Override
    public void success(SPGreat4Bean tb) {
        if (null != tb && null != tb.getBuContractBaseInfo()) {
            spGreat4Bean = tb;
            sp1_normal_code.setText(tb.getBuContractBaseInfo().getCode());
            sp1_normal_name.setText(tb.getBuContractBaseInfo().getName());
            sp1_great_lx.setText(getType(tb.getBuContractBaseInfo().getType()));
            sp1_great_qc.setText(getQicaoType(tb.getBuContractBaseInfo().getQicaoType()));
            sp1_great_zw.setText(getPath(tb.getBuContractBaseInfo().getPath()));
            sp1_great_sz.setText(getSZType(tb.getBuContractBaseInfo().getShouzhiType()));
            if (null != tb.getBuContractBaseInfo().getBuMajorContractSignInfoList() && tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().size() > 0) {
                sp1_great_fen.setText(tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().get(0).getContractCount() + "份");
                sp1_great_sq.setText(tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().get(0).getContractApplyDept().getName());
                sp1_great_zgy.setText(tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().get(0).getContractOfficer().getName());
                sp1_great_creat_time.setText(tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().get(0).getContractApplyDate());
                sp1_great_bz.setText(tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().get(0).getRemarks());
                sp1_normal_main.setText(tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().get(0).getContractOfficer().getName());
                sp1_normal_yj.setText(tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().get(0).getContractDwOfficerOpinion());
                sp1_normal_fg.setText(tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().get(0).getGroupChargeLeader().getName());
                sp1_normal_fg_yj.setText(tb.getBuContractBaseInfo().getBuMajorContractSignInfoList().get(0).getGroupChargeOpinion());
            }
        }
        sp1_normal_scroll.setVisibility(View.VISIBLE);
        dismiss(loadingHorizontal);
    }

    @Override
    public void error() {
        dismiss(loadingHorizontal);
        showError();
    }
}